package com.training.java.core.collections.car.pre15;

/**
 * Purpose of this class to observe the collections using List,ArrayList,Collection.
 * Created multiple school immutable and mutable objects. 
 * Created the Collection using List/ Collection.
 * Added the School1,School2,School3,School4 objects to Collection List interface.
 * Iterate through While loop and Print the school details.
 */

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class SchoolCollectionDemo {

	public static void main(String[] args) {
		// Instantiating and initializing the objects
		// School1,School2,School3,School4

		School school1 = new School("Valley Ranch School", "Irving",
				"Coppell ISD");
		School school2 = new School("Coppell High School", "Irving",
				"Coppell ISD");
		School school3 = new School("Universal Academy", "Irving",
				"Coppell ISD");
		School school4 = new School("NorthHills Prep School", "Irving",
				"Coppell ISD");

		School school5 = new School();// mutable

		// Same object with different Object Name
		School school6 = new School("NorthHills Prep School", "Irving",
				"Coppell ISD");

		// setting the rank to school
		school1.setSchoolRanking(10);
		school2.setSchoolRanking(15);
		school3.setSchoolRanking(12);
		school4.setSchoolRanking(8);
		school5.setSchoolRanking(9);

		// Creating the List Collection

		List schools = new ArrayList();

		// List<School> schools = new ArrayList<School>();

		// Adding objects to Collections.

		schools.add(school1);
		schools.add(school2);
		schools.add(school3);
		schools.add(school4);
		schools.add(school5);
		// Same object with different Object Name
		schools.add(school6);

		// iterating through while loop

		Iterator ite = schools.iterator();

		while (ite.hasNext()) {

			School aSchool = (School) ite.next(); // Type Casting

			// Printing the school details.
			System.out.println("**********************************");
			System.out.println("School Name : " + aSchool.getName());
			System.out.println("City: " + aSchool.getCity());
			System.out.println("School District: "
					+ aSchool.getSchoolDistrict());
			System.out.println("School Ranking :" + aSchool.getSchoolRanking());

		}

	}

}
